﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市管理系统</title>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <style>
        button {
            padding: 7px 30px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #45a049;
        }

        button:active {
            background-color: #3e8e41;
        }
    </style>
</head>
<body>
<!--头部-->
<header class="publicHeader">
    <h1>超市管理系统</h1>

    <div class="publicHeaderR">
        <p><span>下午好！</span><span style="color: #fff21b"> Admin</span> , 欢迎你！</p>
        <a href="logout">退出</a>
    </div>
</header>
<!--时间-->
<section class="publicTime">
    <span id="time">2020年1月1日 11:11  星期一</span>
    <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
</section>
<!--主体内容-->
<section class="publicMian ">
    <div class="left">
        <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
        <nav>
            <ul class="list">
                <li><a href="billList.html">账单管理</a></li>
                <li ><a href="providerList.html">物品管理</a></li>
                <li id="active"><a href="userList.html">用户管理</a></li>
                <li><a href="password.html">密码修改</a></li>
                <li><a href="logout">退出系统</a></li>
            </ul>
        </nav>
    </div>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>用户管理页面 >> 用户添加页面</span>
        </div>
        <div class="providerAdd">
            <form action="#">
                <!--div的class 为error是验证错误，ok是验证成功-->
                <div class="">
                    <label for="nickname">昵称：</label>
                    <input type="text" name="nickname" id="nickname"/>
                    <span>*请输入用户昵称，且不能重复</span>
                </div>
                <div>
                    <label for="username">用户名：</label>
                    <input type="text" name="username" id="username"/>
                    <span >*请输入用户名</span>
                </div>
                <div>
                    <label for="password">用户密码：</label>
                    <input type="text" name="password" id="password"/>
                    <span>*密码长度必须大于6位小于20位</span>
                </div>
                <div>
                    <label for="phone">用户电话：</label>
                    <input type="text" name="phone" id="phone"/>
                    <span >*</span>
                </div>
                <div>
                    <label >用户类别：</label>
                    <input id="f1" type="radio" name="userlei"/>管理员
                    <input id="f2" type="radio" name="userlei"/>普通用户
                </div>
                <div class="providerAddBtn">
                    <!--<a href="#">保存</a>-->
                    <!--<a href="userList.html">返回</a>-->
                    <button>保存</button>
                    <input type="button" value="返回" onclick="history.back(-1)"/>
                </div>
            </form>
        </div>

    </div>
</section>
<footer class="footer">
</footer>
<script src="js/time.js"></script>
<script src="js/axios.min.js"></script>
<script>
    document.querySelector('form').addEventListener('submit', function(e){
        e.preventDefault();

        const username = document.getElementById('username').value;
        const nickname = document.getElementById('nickname').value;
        const password = document.getElementById('password').value;
        const phone = document.getElementById('phone').value;

        var role;
        var f1 = document.getElementById('f1');
        var f2 = document.getElementById('f2');

        if(f1.checked){
            role = 1;
        }else if(f2.checked){
            role = 0;
        }

        axios({
            url: 'register',
            method: 'POST',
            params: {
                nickname,
                username,
                password,
                phone,
                role
            }
        }).then(result =>{
            if(result.data.code === 1){
                alert(result.data.data);
                history.go(-1);
            }else{
                alert(result.data.data);
            }
        })
    });
</script>

</body>
</html>